package org.lookahead.parent.apidoc.mvc;


import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.List;

/**
 * Long型List输出Json，转为逗号，分割的字符串
 */
public class LongArrayToStringSerialize extends JsonSerializer<List<Long>> {

    @Override
    public void serialize(List<Long> values, JsonGenerator gen, SerializerProvider serializer) throws IOException {
        StringBuilder stringBuffer = new StringBuilder();
        for (Long str : values) {
            if (stringBuffer.length() > 0) {
                stringBuffer.append(",");
            }
            stringBuffer.append(str);
        }
        gen.writeString(stringBuffer.toString());
    }
}
